<?
   // make sure google is not going to cache this (igoogle gadget)
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

/*
* UltraMemo Project - GGJsonProxy.php -- controller for google gadgets (igoogle)
*    to allow igoogle gadget to communicate through to google spreadsheet
*
* 11/17/09 initial creation - SPS
* @author Scott Szretter
*/

// private data is actually passed in from the gadget
if(isset($_POST['u'])) $user = $_POST['u'];
if(isset($_POST['p']))$pass= $_POST['p'];
if(isset($_POST['s']))$sheetKey = $_POST['s'];
if(isset($_POST['w']))$worksheetKey = $_POST['w'];

require_once('../PrivateData.php'); // get private data (see SamplePrivateData.php)
require_once('GData.php');
$GData = new GData();
$GData->GDataUser = $user; //from privatedata.php
$GData->GDataPass = $pass; //from privatedata.php
$GData->GDataAuthenticate();
$GData->GDataSSKey=$sheetKey; //from privatedata.php
$GData->GDataWkShtID=$worksheetKey; //from privatedata.php

$JSONOutput="";


// if they just answered a question, update the question
if(isset($_POST['a']) && isset($_POST['q']) && $_POST['q']!=="0" && $_POST['q']!=="" )
{
    include("GG_UpdateQuestion.php");
}

//show a question
include("GG_ShowQuestion.php");

echo '{';

echo $JSONOutput;

echo '}';
?>